from django.db import models
from django.contrib.auth.models import User
from django.contrib import admin
from forfood.address.models import Address
from time import time

class Restaurant(User):
    name = models.CharField(max_length=100)
    phone = models.CharField(max_length=15)
    address = models.ForeignKey(Address)
    description = models.TextField()
    last_update = models.IntegerField()
    loved_by_current = False
    #hot = models.IntegerField(default=3)
    def __unicode__(self):
        return u'%s' % (self.name)      
    def get_manage_path(self):
        return "/restaurant_manage/"
    def is_open(self):
        current = int(time())
        last = self.last_update
        if current-last >= 10:
            return False
        else:       
            return True
    def is_loved_by(self, customer):
        if customer:
            try:
                star = self.star_set.get(customer=customer)
                if star:
                    self.loved_by_current = True
                    return True
            except:
                self.loved_by_current = False
                return False
        self.loved_by_current = False
        return False
class RestaurantAdmin(admin.ModelAdmin):
    pass
admin.site.register(Restaurant, RestaurantAdmin)   
